/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ar.edu.unicen.twitter.suggest.backend.datasources.dao;

import ar.edu.unicen.twitter.suggest.backend.datasources.dao.util.CustomHibernateDaoSupport;
import ar.edu.unicen.twitter.suggest.backend.dtos.OAuthApi;
import ar.edu.unicen.twitter.suggest.commons.dtos.Usuario;
import java.util.List;
import java.util.logging.Logger;

import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

@Repository("configDao")
public class ConfigDaoImpl extends CustomHibernateDaoSupport implements ConfigDao {

    private final static Logger LOGGER = Logger.getLogger(ConfigDaoImpl.class.getName()); 
    
    @Override
    @Transactional
    public void update(OAuthApi auth) {
       OAuthApi result = (OAuthApi) getSession().get(OAuthApi.class, auth.getId());
        if (result == null) {
            getSession().saveOrUpdate(auth);
        } else {
            getSession().merge(auth);
        }
    }
    @Override
    @Transactional
    public void update(List<OAuthApi> auths) {
        for(OAuthApi auth : auths)
            update(auth);
    }
    @Override
    @Transactional
    public List<OAuthApi> getAuthAll(){
        List list = getHibernateTemplate().find(
                "from OAuthApi");
        return (List<OAuthApi>)list;
    }
    @Override
    @Transactional
    public OAuthApi getAuth(Usuario u){
        return (OAuthApi) getSession().get(OAuthApi.class, u.getId());
    }
}